package com.Akronmcp.hta.obj;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.entity.Player;

public class HPar implements Cloneable
{

	String id;
	String text = "";
	HManager hta;
	
	boolean papi = false;
	//是否解析papi
    
    HPar subt;
    //伴随文本
    
    String subtid;
    //伴随文本id
    
    
	
	public HPar(HManager hta)
	{
		this.hta = hta;
		
	}
	public HPar() {}
	
	/**设置id*/
	public void setId(String id)
	{
		   this.id = id;
	}  
	
	public String getId()
    {
		   return this.id;
	}	
	
	/**获取引擎对象*/
	public HManager getManager()
	{
	 return hta;
	}
	
	/**设置是否解析papi*/
	public void setPapi(boolean ispapi)
	{
		this.papi = ispapi;
	}
	
	public boolean isPapi() 
	   {
		
		return papi;
	   }

	/**设置文本*/
	public void setText(String text)
	{
		this.text = text;
		
	}
	
	public String getText()
	{
		return text;
		
	}

	
	/**发送给玩家*/
	public void send(List<Player> pl) {};
	
	/**发送给所有玩家*/
	public void sendToAll() {};
	
	/**设置伴随文本*/
	public void setSubText(String htid)
	{
		subtid = htid;
	}
	
	public HPar getSubText()
	{
		return subt;
	}
	public String getSubTextid()
	{
		return subtid;
	}
	
	public void setSubText(HPar ht)
	{	
		subt = ht;
	}
	
	
	/**发送伴随文本*/
	public void sendSubtext(List<Player> pl)
	{
		if(subtid!=null)
		{//后联系结构,运行时再调用
			if(subtid.startsWith("hchat:"))
			subt=hta.getHopChat(subtid.substring(6));
			
			if(subtid.startsWith("htitle:"))
			subt=hta.getHopTitle(subtid.substring(7));
			
			if(subtid.startsWith("hbar:"))
			subt=hta.getHopBar(subtid.substring(5));
			
			if(subtid.startsWith("hbook:"))
			subt=hta.getHopBook(subtid.substring(6));
		}
		if(subt!=null)		
		subt.send(new ArrayList<Player>(pl));
	}
	
	/**发送伴随文本*/
	public void sendSubtext(Player p)
	{
		sendSubtext(Arrays.asList(p));
	}
	
	/**发送伴随文本*/
	public void send(Player p)
    {
    	if(p!=null&&p.isOnline())
    	{
    	  send(Arrays.asList(p));
    	}
    	sendSubtext(p);
    }
	
	
	/**浅克隆*/
	public Object clone() 
	 {//浅克隆,足矣
	     Object o = null;
	    try 
	    {
	        o = super.clone();
	        
	    } catch (CloneNotSupportedException e) 
	    {
          e.printStackTrace();
        }
         return o;
     }

	public void setManager(HManager hta)
	{
		this.hta = hta;
	}
	

}

